const transformMd = require('./transformMd')
const transformReadme = require('./transformReadme')
const transformSidebar = require('./transformSidebar')
const transformJS = require('./transformJS')

class Transform {
  constructor() {
    this.data = []
  }
  add(reg, callback, ...args) {
    if (reg instanceof RegExp) {
      this.data.push([reg, callback, args])
    }
  }
  implement(k, ...arg) {
    for (let i = 0; i < this.data.length; i++) {
      const [reg, fn, args = []] = this.data[i];
      if (reg.test(k)) {
        return fn.apply(null, arg.concat(args))
      }
    }
  }
}
const transform = new Transform()
transform.add(/README.md$/, transformReadme)
transform.add(/sidebar.md$/, transformSidebar)
transform.add(/.js.md$/, transformJS)
transform.add(/.md$/, transformMd)

module.exports = transform